package main

import (
	"fmt"
	"time"
)

func main() {

	c1 := make(chan string)
	c2 := make(chan string)
	c3 := make(chan int)

	go func() {
		time.Sleep(1 * time.Second)
		c1 <- "one"
	}()
	go func() {
		time.Sleep(2 * time.Second)
		c2 <- "two"
	}()

	msg3 := 123
	for i := 0; i < 3; i++ {
		select {
		case msg1 := <-c1:
			fmt.Println("received", msg1)
		case msg2 := <-c2:
			fmt.Println("received", msg2)
		case c3 <- msg3:
			fmt.Println("send", 678)
		}
	}
}

/*
select {
case msg1 := <-ch1:
    // 从通道 ch1 接收数据
    fmt.Println("Received", msg1)
case ch2 <- msg2:
    // 向通道 ch2 发送数据
    fmt.Println("Sent", msg2)
case msg3, ok := <-ch3:
    // 使用ok判断通道是否已关闭，并接收数据
    if ok {
        fmt.Println("Received", msg3)
    } else {
        fmt.Println("Channel closed")
    }
default:
    // 当没有任何通道准备好时执行的代码
    fmt.Println("No communication")
}
*/
